import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import cookie from 'js-cookie'

const whiteRouterList = ['/Login']

router.beforeEach((to, from, next) => {
  NProgress.start()
  document.title = to.meta.title
  // 查找localStorage存储    cookie.get
  if (cookie.get('Xd_Token')) {
    if (to.path === '/Login') {
      next({
        path: from.path
      })
    } else {
      next()
    }
    NProgress.done()
  } else {
    if (whiteRouterList.indexOf(to.path) !== -1) {
      next()
    } else {
      next({
        name: 'Login',
        query: {
          redirect: to.fullPath
        }
      })
    }
    NProgress.done()
  }
  next()
})
// 页面加载完成
router.afterEach((to, from) => {
  NProgress.done()
})